# Copyright 2024 The Pigweed Authors
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
#     https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.

load("@rules_python//python:proto.bzl", "py_proto_library")
load("//pw_protobuf_compiler:pw_proto_library.bzl", "pw_proto_library")

package(default_visibility = ["//visibility:public"])

licenses(["notice"])

constraint_value(
    name = "support_backend",
    constraint_setting = "//pw_cpu_exception:support_constraint_setting",
)

cc_library(
    name = "config",
    hdrs = ["pw_cpu_exception_risc_v_private/config.h"],
    deps = [":config_override"],
)

label_flag(
    name = "config_override",
    build_setting_default = "//pw_build:default_module_config",
)

cc_library(
    name = "cpu_state",
    hdrs = ["public/pw_cpu_exception_risc_v/cpu_state.h"],
    includes = ["public"],
    deps = [
        "//pw_preprocessor",
    ],
)

cc_library(
    name = "support",
    srcs = ["support.cc"],
    deps = [
        ":config",
        ":cpu_state",
        "//pw_cpu_exception:support.facade",
        "//pw_log",
        "//pw_preprocessor",
        "//pw_string",
    ],
)

cc_library(
    name = "proto_dump",
    srcs = ["proto_dump.cc"],
    hdrs = ["public/pw_cpu_exception_risc_v/proto_dump.h"],
    includes = ["public"],
    deps = [
        ":config",
        ":cpu_state",
        ":cpu_state_protos_cc.pwpb",
        ":support",
        "//pw_protobuf",
        "//pw_status",
        "//pw_stream",
    ],
)

proto_library(
    name = "cpu_state_protos",
    srcs = ["pw_cpu_exception_risc_v_protos/cpu_state.proto"],
    import_prefix = "pw_cpu_exception_risc_v_protos",
    strip_import_prefix = "/pw_cpu_exception_risc_v/pw_cpu_exception_risc_v_protos",
)

py_proto_library(
    name = "cpu_state_protos_pb2",
    deps = [":cpu_state_protos"],
)

pw_proto_library(
    name = "cpu_state_protos_cc",
    deps = [":cpu_state_protos"],
)

cc_library(
    name = "snapshot",
    srcs = ["snapshot.cc"],
    hdrs = ["public/pw_cpu_exception_risc_v/snapshot.h"],
    deps = [
        ":config",
        ":cpu_state",
        ":cpu_state_protos_cc.pwpb",
        ":proto_dump",
        "//pw_log",
        "//pw_protobuf",
        "//pw_status",
        "//pw_thread:snapshot",
        "//pw_thread:thread_cc.pwpb",
    ],
)
